# TS平台我的组员明细数据比邻有惠老带新

import time

from Common.basepage import BasePage
from PageLocators.TS.ts_my_team_member_loc import DetailOfMyTeam as dt_loc
from TestDatas.TsDatas.ts_mystudents_datas import ts_row_link_loc_data
from PageObjects.tools import replace_loc
from Common.dir_config import audio_dir, img_dir


class TsMyTeamMemberPage(BasePage):
    """TS班主任工作平台我的学员"""

    def change_module_page(self, nb1_loc=None, nb2_loc=None,
                           attr_name='class', attr_value='parent-active', nb1_name='', nb2_name=''):
        """
        选择模块页面--导航栏
        :param nb1_loc: 一级导航栏模块定位 # navigation bar 导航栏
        :param nb2_loc: 二级导航栏模块定位
        :param attr_name: 属性名
        :param attr_value: 一级导航栏展开的属性值，默认参数class属性值
        :param nb1_name: 一级导航模块名称
        :param nb2_name: 二级导航模块名称
        """
        time.sleep(5)
        attr_values = self.get_element_attribute(nb1_loc, attr_name, "获取导航栏属性值用于判断一级导航是否展开")
        print('attr_values----', attr_values)
        if attr_value in attr_values:
            self.click_element(nb2_loc, "点击AR二级导航-{}".format(nb2_name))
        else:
            self.click_element(nb1_loc, "点击AR一级导航-{}".format(nb1_name))
            time.sleep(1)
            self.click_element(nb2_loc, "点击AR二级导航-{}".format(nb2_name))
        time.sleep(2)

    # TS我的组员
    def go_my_team_nav(self):
        """打开英文课程学员二级导航页面"""
        self.change_module_page(nb1_loc=dt_loc.nav_my_team_member_loc, nb2_loc=dt_loc.nav_detail_data_loc,
                                attr_name='style', attr_value='90deg', nb1_name='我的组员', nb2_name='我的组员明细数据')

    def go_old_with_new(self):
        """比邻有惠老带新tab标签页"""
        self.driver.execute_script(dt_loc.content_head)  # 横向滑动滚动条至比邻有惠tab
        time.sleep(1)
        self.click_element(dt_loc.old_with_new_loc, "点击比邻有惠老带新", sleep_time=3)

    def search_old_with_new(self):
        """老带新页面数据搜索"""
        self.click_element(dt_loc.start_time_loc, "时间范围-开始时间", sleep_time=3)
        self.click_element(dt_loc.month_loc, "时间范围-开始时间-1月", sleep_time=3)
        self.click_element(dt_loc.poster_role_loc, "点击选择分享海报角色", sleep_time=3)
        self.click_element(dt_loc.role_loc, "点击选择分享海报角色-选择教师端", sleep_time=3)
        self.click_element(dt_loc.search_loc, "点击搜索", sleep_time=3)

    def business_result(self):
        """商机明细-结果验证"""
        self.click_element(dt_loc.total_business_loc, "点击合计商机查看按钮", sleep_time=5)
        bus_data = self.get_element_text(dt_loc.detail_dialog_loc, "老带新明细数据table列表数据文本")
        return bus_data

    def close_alert(self):
        """云呼已有设备注册， 是否强制登录弹窗处理"""
        try:
            self.click_element(dt_loc.alert_cancel_loc, "云呼弹窗关闭-取消", sleep_time=3)
        except:
            pass
